package com.gosophia.accountManagement.action;

import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.userManagement.dto.PermissionDTO;
import com.gosophia.userManagement.dto.RoleDTO;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 跳转到新建页面action
 * @author mayue
 *
 */
@Controller("ToCreatePageAction")
@Scope("prototype")
public class ToCreatePageAction extends BaseSupportAction {
    
    private static final long serialVersionUID = 1L;
    
    @Autowired
    private UserManagementWebService userManagementWebService;
    //账号使用者列表(List<UserInfoDTO>)
    private String accountUsersJsonString;
    //可使用的账号角色
    private List<RoleDTO> canUserRoles;
    //账号权限(List<PermissionDTO>)
    private String accountPermissionJsonString;
    
    
    @Override
    public String _execute() throws Exception {
        //刷使用者
        List<UserInfoDTO> userInfoDTOs = userManagementWebService.findAllUserInfo();
        if(userInfoDTOs!=null&&userInfoDTOs.size()!=0){
            accountUsersJsonString = JSONArray.fromObject(userInfoDTOs).toString().replace("\"", "\\\"");
        }
        //刷角色（需要改为找没有账号的所有用户）
        canUserRoles = userManagementWebService.findAllRole();
        
        //刷权限
        List<PermissionDTO> permissionDTOs = userManagementWebService.findAllPermission();
        if(permissionDTOs!=null && permissionDTOs.size()!=0){
            accountPermissionJsonString = JSONArray.fromObject(permissionDTOs).toString().replace("\"", "\\\"");
        }
        return SUCCESS;
    }
    public String getAccountUsersJsonString() {
        return accountUsersJsonString;
    }
    public void setAccountUsersJsonString(String accountUsersJsonString) {
        this.accountUsersJsonString = accountUsersJsonString;
    }
    public List<RoleDTO> getCanUserRoles() {
        return canUserRoles;
    }
    public void setCanUserRoles(List<RoleDTO> canUserRoles) {
        this.canUserRoles = canUserRoles;
    }
    public String getAccountPermissionJsonString() {
        return accountPermissionJsonString;
    }
    public void setAccountPermissionJsonString(String accountPermissionJsonString) {
        this.accountPermissionJsonString = accountPermissionJsonString;
    }
    
}
